package com.mantru.iotpot.Util

import android.content.Context
import android.util.Log
import com.hzmct.enjoysdk.api.EnjoySDK
import com.mc.android.mcinstall.AppRule

object MotherboardUtil {
    //只需要调用就可以初始化，不需要额外操作
    fun initMotherboard(context: Context){
        //调用主板厂家SDK
        val enjoySDK = EnjoySDK(context)
        val appRule = AppRule("com.mantru.iotpot", false)
        Log.e("---appRule", appRule.toString())
        //获取当前 "SecurePassword" 的设置状态
        val ret1 = enjoySDK.securePasswdStatus
        Log.e("---ret1", ret1.toString())
        //设置密码
        val ret4 = enjoySDK.setSecurePasswd("Abc12345","Abc12345")
        Log.e("---ret4", ret4.toString())
        //注册当前应用为安全密码应用
        val ret2 = enjoySDK.registSafeProgram("Abc12345")
        Log.e("---ret2", ret2.toString())
        //添加白名单并返回白名单列表
        val appRuleList = enjoySDK.addWhiteRules(appRule)
        Log.e("---appRuleList", appRuleList.toString())
        //开启白名单
        val retWhite = enjoySDK.whiteRulesSwitch(true)
        Log.e("---retWhite", retWhite.toString())
        //判断使用启用白名单
        val status = enjoySDK.isEnableWhiteRules
        Log.e("---status", status.toString())
        //设置静默安装开关状态
        val ret = enjoySDK.silentInstallRulesSwitch(true)
        Log.e("---ret", ret.toString())
        //获取静默安装开关状态
        val statusSilent = enjoySDK.isEnableSilentInstallRules
        Log.e("---statusSilent", statusSilent.toString())
        //添加APP至静默安装列表中
        val silentInstallList = enjoySDK.addSilentInstallRules(appRule)
        Log.e("---silentInstallList", silentInstallList.toString())
        //设置安装后启动开关状态
        val retInstallList = enjoySDK.installAutoStartSwitch(true)
        Log.e("---retInstallList", retInstallList.toString())
        //添加应用至 安装后启动 应用列表中
        val arrayList = enjoySDK.addInstallAutoStartRules(appRule)
        Log.e("---arrayList", arrayList.toString())
    }

    fun showBarState(context: Context, show: Boolean){
        val enjoySDK = EnjoySDK(context)
        //获取当前 "SecurePassword" 的设置状态
        val ret1 = enjoySDK.securePasswdStatus
        Log.e("---ret1", ret1.toString())
        //设置密码
        val ret4 = enjoySDK.setSecurePasswd("Abc12345","Abc12345")
        Log.e("---ret4", ret4.toString())
        //注册当前应用为安全密码应用
        val ret2 = enjoySDK.registSafeProgram("Abc12345")
        Log.e("---ret2", ret2.toString())
        enjoySDK.setStatusBarShowStatus(show)
        val showInt = if ( show ){
            1
        } else {
            0
        }
        val ret = enjoySDK.setNavigationBarShowStatus(showInt)
        Log.e("---ret", ret.toString())
        //同时把状态记录本地
        SharePreUtil.saveStringData(context, "barState", show.toString())
    }
}